package com.mercury.coffee.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mercury.coffee.entity.PushCoffeeLabel;
import com.mercury.coffee.mapper.PushCoffeeLabelMapper;
import com.mercury.coffee.service.PushCoffeeLabelService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mercury.coffee.service.PushCoffeeTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 童雅婷
 * @since 2021-11-07
 */
@Service
public class PushCoffeeLabelServiceImpl extends ServiceImpl<PushCoffeeLabelMapper, PushCoffeeLabel> implements PushCoffeeLabelService {

    @Autowired
    private PushCoffeeTypeService coffeeTypeService;

    /**
     * @date 2021/11/7 20:14
     * @params coffeeId
     * @return
     * @description 根据 coffee id 找到所有的 标签id 并且获得其名称
    */
    @Override
    public List<String> selectById(Integer coffeeId) {
        //找到该 coffee 的所有标签id
        HashMap<String, Object> map = new HashMap<>();
        map.put("coffee_id", coffeeId);
        List<PushCoffeeLabel> coffeeLabels = baseMapper.selectByMap(map);
        List<String> coffeeTypes = new ArrayList<>();
        for (PushCoffeeLabel coffeeLabel : coffeeLabels) {
            //根据标签id 获得所有的名称
            String type = coffeeTypeService.selectNameById(coffeeLabel.getCoffeeLabel());
            coffeeTypes.add(type);
        }
        return coffeeTypes;
    }
}
